package com.geostar.constructionland.index.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.geostar.constructionland.index.entity.model.IndexAdjustModel;
import com.geostar.constructionland.index.entity.model.IndexSupplementModel;
import com.geostar.constructionland.index.entity.server.ServerResponse;
import com.geostar.constructionland.index.entity.vo.IndexSupplementListData;
import com.geostar.constructionland.index.service.IndexAdjustService;
import com.geostar.constructionland.index.service.IndexSupplementService;
import com.geostar.constructionland.index.util.FormatUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/***
 * 指标补录
 * @author wuyongzhi
 */
@RestController
@RequestMapping("/indexSupplement")
@Api(tags = "指标补录相关接口")
public class IndexSupplementController {

    @Resource
    IndexAdjustService indexAdjustService;
    @Resource
    IndexSupplementService indexSupplementService;

    @ApiOperation(value = "获取指标补录信息列表", notes = "获取指标补录信息列表，必须设置分页参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum", value = "页码", required = true),
            @ApiImplicitParam(name = "pagesize", value = "页数", required = true),
            @ApiImplicitParam(name = "distCodeProvince", value = "省区划代码", required = true),
            @ApiImplicitParam(name = "distCodeCity", value = "市区划代码"),
            @ApiImplicitParam(name = "distCodeCountry", value = "县区划代码"),
            @ApiImplicitParam(name = "indexYear", value = "指标年度"),
            @ApiImplicitParam(name = "sortOrder", value = "排序类型 "),
            @ApiImplicitParam(name = "sortName", value = "排序字段 "),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public IPage<IndexSupplementListData> queryInxStorageList(@Valid IndexSupplementModel indexSupplementModel) {
        return indexSupplementService.queryIndexSupplementList(indexSupplementModel);
    }

    @ApiOperation(value = "新增或者更新补录指标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inxStorageId",value = "入库指标id"),
            @ApiImplicitParam(name = "adjustIndexId",value = "调整指标id"),
            @ApiImplicitParam(name = "distCode",value = "行政区划代码"),
            @ApiImplicitParam(name = "distName",value = "行政区划名称"),
            @ApiImplicitParam(name = "distCodeProvince",value = "省级行政区划代码"),
            @ApiImplicitParam(name = "distCodeCity",value = "市级行政区划代码"),
            @ApiImplicitParam(name = "distCodeCountry",value = "县级行政区划代码"),
            @ApiImplicitParam(name = "projectName",value = "项目名称"),
            @ApiImplicitParam(name = "approvalNum",value = "批准文号"),
            @ApiImplicitParam(name = "approvalTime",value = "批准日期"),
            @ApiImplicitParam(name = "approvalAuthority",value = "批准机关"),
            @ApiImplicitParam(name = "totalProjectArea",value = "项目总面积"),
            @ApiImplicitParam(name = "buildLandAdd",value = "新增建设用地"),
            @ApiImplicitParam(name = "agclLand",value = "农用地"),
            @ApiImplicitParam(name = "farmland",value = "耕地"),
            @ApiImplicitParam(name = "remark",value = "备注"),
            @ApiImplicitParam(name = "indexType",value = "指标类型"),
            @ApiImplicitParam(name = "operatorId",value = "操作人ID"),
            @ApiImplicitParam(name = "businessId",value = "业务id")
    })
    @PostMapping(value = "/insertOrUpdateAdjustIndex")
    @ResponseBody
    public ServerResponse insertOrUpdateAdjustIndex(@Valid IndexAdjustModel indexAdjustModel) {
        indexAdjustService.insertOrUpdateAdjustIndex(indexAdjustModel);
        return ServerResponse.createBySuccess();
    }

    @ApiOperation(value = "根据id集合删除补录指标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inxStorageId", value = "入库指标id集合（多个以英文“,”分割）", required = true),
            @ApiImplicitParam(name = "adjustIndexId", value = "调整指标id集合（多个以英文“,”分割）", required = true)
    })
    @PostMapping(value = "/delete")
    @ResponseBody
    public ServerResponse deleteByInxStorageAcotByIds(@Valid IndexAdjustModel indexAdjustModel) {
        ServerResponse serverResponse = ServerResponse.createBySuccess();
        List<String> inxStorageIdList = FormatUtils.getStringByList(indexAdjustModel.getInxStorageId());
        List<String> adjustIndexIdList = FormatUtils.getStringByList(indexAdjustModel.getAdjustIndexId());
        if(inxStorageIdList.size() == adjustIndexIdList.size()) {
            indexAdjustService.deleteAdjustIndexByIds(inxStorageIdList, adjustIndexIdList);
        } else {
            serverResponse = ServerResponse.createByErrorMessage("传入参数有误：待删除的入库指标数量与调整指标数量不一致！");
        }
        return serverResponse;
    }

}
